#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int calPoints(vector<string>& operations) {
        vector<int> v1;
        for (auto& e : operations)
        {
            if (e[0] < 58 && e[0] != '+')
            {
                v1.push_back(stoi(e));
                //cout << "<58" << endl;
            }
            else if (e[0] == 'C')
            {
                v1.pop_back();
                //cout << "C" << endl;
            }
            else if (e[0] == 'D')
            {
                v1.push_back(v1[v1.size() - 1] * 2);
                //cout << "D" << endl;
            }
            else
            {
                v1.push_back(v1[v1.size() - 1] + v1[v1.size() - 2]);
                //cout << "+" << endl;
            }
        }
        int sum = 0;
        for (auto& e : v1)
        {
            sum += e;
        }

        return sum;
    }
};